<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>添加美容院</title>
  <link rel="stylesheet" href="../../../layui/css/layui.css">
  <script src="../../../layui/layui.js"></script>
    <script type="text/javascript" src="../../../js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="../../../js/main.js"></script>
</head>
<style type="text/css">
 body{
  height: 100%;
  width: 100%;
 }
 .layui-form-label{width: 130px}
 .btn {
    background-color: #e5e5e5;
    background-image: none;
    filter: none;
    border: 0;
    padding: 7px 14px;
    text-shadow: none;
    font-family: "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: #333333;
    cursor: pointer;
    outline: none;
    -webkit-box-shadow: none !important;
    -moz-box-shadow: none !important;
    box-shadow: none !important;
    -webkit-border-radius: 0 !important;
    -moz-border-radius: 0 !important;
    border-radius: 0 !important;
}
.layui-input-inline{width: 214px !important}
    upload.render({
     elem: '.test'
        ,done: function(res, index, upload){
      //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
     var item = this.item;
  }
    })
</style>

<body>
 <!-- 内容主体区域 -->
 <div class="x-body layui-anim layui-anim-up">
  <div class="layui-fluid">
  
    <form class="layui-form layui-form-pane1" lay-filter="first">
        <div class="layui-form-item">
        </div>
      <div class="layui-form-item">
         <label class="layui-form-label"><span class="text-error">*</span>美容院名称：</label>
         <div class="layui-input-inline">
          <input name="salonName" id="salonName" placeholder="请输入" value="" class="layui-input">
          </div>
      </div>
       <div class="layui-form-item">
         <label class="layui-form-label"><span class="text-error">*</span>联系电话：</label>
         <div class="layui-input-inline">
          <input name="tel" id="tel" placeholder="请输入"  value="" class="layui-input">
          </div>
      </div>

        <div class="layui-form-item">
            <label class="layui-form-label">是否上门服务：</label>
            <div class="layui-input-block">
                <input type="checkbox" name="door2Door"  id="door2Door" lay-skin="switch">
            </div>
        </div>
      <div class="layui-form-item">
         <label class="layui-form-label">地址：</label>
         <div class="layui-input-inline">
          <input name="address" id="address" placeholder="请输入"  value="" class="layui-input">
          </div>
      </div>
        <div>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="pic">多图片上传</button>
               <!-- <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    预览图：
                    <div class="layui-upload-list" id="demo2"></div>
                </blockquote>-->
            </div>

        </div>
        <div class="layui-form-item" style="margin-left: 140px;">
            <!--<p id="btnGroup" class="pull-right">-->
                <button class="layui-btn save"  lay-submit="" lay-filter="*" id="save">保存</button>
                <button class="layui-btn quxiao" >取消</button>
            <!--</p>-->
        </div>
        <input name="recordId" id="recordId"  type="hidden" value="" class="layui-input">
    </form>
  </div>
  </div>
  </body>
  </html>
<script type="text/javascript">

    // function child(data){
    //     var $ = layui.jquery;
    //     var userCode = data.userCode;
    //     $('#userCode').val(userCode);
    //     var userName = data.userName;
    //     $('#userName').val(userName);
    //
    //     var recordId = data.recordId;
    //     $('#recordId').val(recordId);
    //
    //     var userStatus = data.userStatus;
    //     if(userStatus==1){
    //         $("#userStatus").attr("checked",'checked');
    //     }
    //     var email = data.email;
    //     $('#email').val(email);
    //
    //     console.log(data);
    // }

    //全局变量
    var picId,picUrl,salonId;
    var picIds="";
     //var salonId = new Array(3);

    layui.use(['element', 'layer', 'jquery','form','laydate','upload'], function () {
	  var form = layui.form;
	  var $ = layui.jquery;
	  var laydate=layui.laydate;
	  /* function quxiao(){
	  	alert(111);
	  } */
	   var $ = layui.jquery,
	   upload = layui.upload;

	  form.on('submit(*)', function(data){
	  	console.log(data.field);
	  	if(data.field.door2Door=='on'){
            data.field.door2Door = true;
        }else{
            data.field.door2Door = false;
        }

           var url = '/hy/basic/salon/createSalon';



          $.ajax({
              type:'POST',
              url:url,
              data: data.field,
              dataType:"json",
              success: function(data){

                //获取salonId;
                 for(var key in data.data){
                    salonId=data.data[key].salonId;
                 }
                 //修改图片绑定的店铺id
                 updatePic(picIds,picUrl,salonId);


                  var dataJson=JSON.stringify(data);

                  console.log("+++"+JSON.stringify(data));
                  console.log(data.data);
                  if(data.data.msgcode == '200'){

                      alert(data.data.msg);
                      alert("salonId"+dataJson)
                  }else{
                      alert("操作成功！");
                      window.parent.location.reload(); //刷新父页面
                      var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                      parent.layer.close(index);  // 关闭layer
                  }


              },
              error:function(data){
                  alert("操作失败");
                  console.log(data);
              }
          })


          return false;
	  });

})

//图片上传
//多图片上传
layui.use('upload', function(){
  var $ = layui.jquerys
  ,upload = layui.upload;

  upload.render({
    elem: '#pic'
    ,url: '/hy/basic/SalonPictures/uploadServicePic'
    ,data :{'recordType' : 0,'picType':0}
    ,multiple: true
    ,number:3
    ,auto: false
    ,bindAction:'#save'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){


      });
    }
    ,done: function(res,index){
      //上传完毕


       for(var key in res.data){
        // alert("属性：" + key + ",值：" + res.data[key]);
         if(key == "data"){
            picId=res.data[key].picId;

            picUrl=res.data[key].picUrl;
            //把图片id拼接
            picIds = picIds + picId+",";

         }
       }
    }
  });
 });


function updatePic(picId,picUrl,salonId){
    alert("updatePic"+picId)
     $.ajax({
              type:'POST',
              url:'/hy/basic/SalonPictures/uploadPicForPC',
              data: { 'picId' :picId,'picUrl':picUrl,"masterDataId": salonId , 'picType': 0 ,'recordType': 0},
              dataType:"json",
              success: function(data){

              },
              error:function(data){
                  alert("操作失败");
                  console.log(data);
              }
          })



}





</script>